package part4createthread;

/**
 * @description: 观察测试线程的状态
 * @author: zhang hang
 * @date: 2022/10/6 13:55.
 * @version: 1.0
 */
public class ThreadStateDemo01 {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Logic Over");
        });
        System.out.println("线程当前状态为：" + thread.getState());
        thread.start();
        System.out.println("线程当前状态为：" + thread.getState());
        while (thread.getState() != Thread.State.TERMINATED) {
            Thread.sleep(100);
            System.out.println("线程当前状态为：" + thread.getState());
        }
    }

}
